<style type="text/css">
body,td,th {
	font-size: 14px;
}
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
table {
	border-collapse:collapse;
}
a:link {
	color: #603;
	text-decoration: none;
}
a:visited {
	text-decoration: none;
	color: #603;
}
a:hover {
	text-decoration: none;
	color: #F00;
}
a:active {
	text-decoration: none;
	color: #F00;
}
#create {
	text-align:right;
}
.spile-page1 {
	float: left;
	width:45px;
	text-align:center;
}
.spile-page2 {
	background-color:#69F;
	color:#FFF;
	float: left;
	width:45px;
	text-align:center;
}
.spile-page3 {
	float: left;
	width:30px;
	text-align:center;
}
.spile-page4 {
	background-color:#69F;
	color:#FFF;
	float: left;
	width:30px;
	text-align:center;
}
.spile-page1-desable {
	float: left;
	width: 45px;
}
</style>
<?php
// config variable
$p = basename ( $_SERVER ['PHP_SELF'] );
$pb = substr ( $p, 0, - 4 );
$op = $pb . '_action.php';
/*
// variable
$aInter = array();
$aUnit = array();
$aLink = array();
$param ='';
$pSize = 5;
$pNum = 5;
*/
$subfile="sub_{$p}";
if (file_exists($subfile)) {include $subfile;exit;}
require '~cache.php';
require '~page.php';
require 'conf.php';
echo GetHead ();

if (! isset ( $conf [$pb] ) or empty ( $conf [$pb] ) or ! is_array ( $conf [$pb] ))
	die ( 'Please edit the <i>config file</i> first' );
extract ( $conf [$pb], EXTR_PREFIX_SAME, 'conf' );
empty ( $sqlTalbe ) && $sqlTalbe = $pb;
empty ( $sqlPre ) && $sqlPre = $sqlTalbe;
$sqlId = $sqlPre . '_id';
$tmp=array();
foreach ( $aInter as $v )
	$tmp [] = $sqlPre . '_' . $v;
!empty ( $tmp ) && $aInter = $tmp;

// catch get params
$p = isset ( $_GET ['page'] ) ? $_GET ['page'] : 1;
$order = isset ( $_GET ['o'] ) ? $_GET ['o'] : $sqlId;
$b = isset ( $_GET ['b'] ) ? $_GET ['b'] : 0;
$stable = isset ( $_GET ['t'] ) ? $_GET ['t'] : '';
$sid = isset ( $_GET ['i'] ) ? $_GET ['i'] : '';
$gets = array_diff_key ( $_GET, array_flip ( array ('page', 'o', 'b', 't', 'i' ) ) );

// handle params
$by = $b ? 'DESC' : 'ASC';
$sParams = '';
$tParams = '&';
foreach ( $gets as $k => $v ) {
	$sParams .= "and $k='$v' ";
	$tParams .= "$k='$v'&";
}
$sParams .= " order by $order $by";
$pParams = "b=$b&o=$order$tParams&t=$stable&i=$sid";

if (! empty ( $stable ) && ! empty ( $sid )) {
	$sql = "select $sqlTalbe.* from relation,$sqlTalbe where (relation_t1='$stable' and relation_t2='$sqlTalbe' and relation_r1='$sid' and relation_r2=$sqlId) or (relation_t1='$sqlTalbe' and relation_t2='$stable' and relation_r1=$sqlId and relation_r2='$sid') ";
} else {
	$sql = "select * from $sqlTalbe where 1 ";
}
$sql .= $sParams;

// set and get data
$page = new page ();
$page->set_pagesize ( $pSize ); 
$page->set_pagenumber ( $pNum );
$page->set_setpage ( $p );
$page->set_params ( $pParams );
$value = $page->get_result ( $sql );
$value = FormatListWithViewLink ( $value, $aLink, $pb );
# should delete
$aInter = empty ( $aInter ) ? array_keys ( GetFieldsInfoByTable ( $sqlTalbe ) ) : $aInter;
$keyinfo = GetFieldComment ( $sqlTalbe, array_flip ( $aInter ) );

// view
ViewListAsTableA ( $keyinfo, $value, $aUnit, $tParams );
$page->showpage ();
$page->jumptopage ();

echo GetFoot ();
